import {
  HTTP
} from '../utils/http.js';

class ContentModel extends HTTP {

  /**
   * 根据ID查询
   * @param {Long} id 
   */
  getOne(id) {
    return this.request({
      url: `contentIndex/${id}`
    });
  }

  /**
   * 查询用户下内容
   * @param {Long} userId 
   * @param {Integer} pageNum 
   * @param {Integer} pageSize 
   */
  getUserContents(userId, pageNum, pageSize = 50) {
    return this.request({
      url: `contentIndex/user/${userId}`,
      data: {
        "pageNum": pageNum,
        "pageSize": pageSize
      }
    });
  }

  /**
   * 搜索
   * @param {String} content 
   * @param {Long} pageNum 
   * @param {Long} pageSize 
   */
  search(content, pageNum, pageSize = 50) {
    return this.request({
      url: "contentIndex/search",
      data: {
        "content": content,
        "pageNum": pageNum,
        "pageSize": pageSize
      }
    })
  }

  /**
   * 我的历史
   * @param {Long} pageNum 
   * @param {Long} pageSize 
   */
  myHistory(pageNum, pageSize = 50) {
    return this.request({
      url: "contentIndex/history",
      data: {
        "token": wx.getStorageSync('token'),
        "pageNum": pageNum,
        "pageSize": pageSize
      },
      method: 'POST'
    })
  }

  /**
   * 我的收藏
   * @param {Long} pageNum 
   * @param {Long} pageSize 
   */
  myCollect(pageNum, pageSize = 50) {
    return this.request({
      url: "contentIndex/collect",
      data: {
        "token": wx.getStorageSync('token'),
        "pageNum": pageNum,
        "pageSize": pageSize
      },
      method: 'POST'
    })
  }

  /**
   * 内容详情推荐
   * @param {String} content 内容标题
   * @param {Long} contentId 内容ID
   * @param {Long} userId 用户ID
   * @param {Array} tags 标签
   */
  detailRecommend(content, contentId, userId, tags) {
    return this.request({
      url: "contentIndex/detailRecommend",
      data: {
        "token": wx.getStorageSync('token'),
        "content": content,
        "contentId": contentId,
        "userId": userId,
        "tags": JSON.stringify(tags)
      },
      method: 'POST'
    })
  }

}

export {
  ContentModel
}